<?php

use App\Modules\Ecommerce\Models\Product;
use App\Modules\Ecommerce\Models\Category;

class ProductTableSeeder
extends \App\Modules\Ecommerce\Seeds\DatabaseSeeder
{
  public function run()
  {
    $faker = $this->getFaker();

    $categories = Category::all();

    foreach ($categories as $category)
    {
      for ($i = 0; $i < rand(-1, 10); $i++)
      {
        $name  = ucwords($faker->word);
        $stock = $faker->randomNumber(0, 100);
        $price = $faker->randomFloat(2, 5, 100);

        Product::create([
          "name"        => $name,
          "stock"       => $stock,
          "price"       => $price,
          "category_id" => $category->id
        ]);
      }
    }
  }
}